<template>
	<div class="sw_section_container" v-loading="loading">
		<div class="sw_query_form" v-if="$isHasAuth(topFrames)">
			<template v-if="userRole === 'member'">
				<div class="button" v-if="$isHasAuth(topButton)">
					<el-button type="primary" icon="el-icon-plus" v-hasPermi="'ec854d2ad50a47ffbb61dec5879ff892'" @click="handleOpenForm()">添加成果</el-button>
					<template v-if="checkedData.length > 0">
						<el-button type="danger" icon="el-icon-delete" v-hasPermi="'4853ba8c62a44e00ad52a9f79d71ca14'" @click="handleBacthDelete()">
							删除
						</el-button>
					</template>
				</div>
			</template>
			<el-form size="small" inline v-hasPermi="queryBtn">
				<el-form-item>
					<el-input v-model="queryData.filed1" clearable placeholder="成果名称" style="width: 180px"></el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" icon="el-icon-search" @click="queryTableData">查询</el-button>
				</el-form-item>
			</el-form>
		</div>
		<div class="sw_table_container">
			<el-table size="medium" ref="table" :data="tableData" height="100%" class="index_table_wrapper" @selection-change="handleSelectionChange">
				<el-table-column type="selection" width="48" align="center" :selectable="selectableChecked"></el-table-column>
				<el-table-column label="成果状态" width="90" :formatter="statusFormatter"></el-table-column>
				<el-table-column label="成果类型" min-width="108" sortable :formatter="achievementTypeFormatter" />
				<el-table-column label="成果名称" prop="filed1" min-width="196" sortable></el-table-column>
				<el-table-column label="所属课题" prop="name" min-width="196" sortable></el-table-column>
				<el-table-column label="成果时间" prop="filed4" min-width="109" sortable></el-table-column>
				<el-table-column label="申请人" prop="createName" width="100" sortable></el-table-column>
				<el-table-column label="操作" :width="$controlWidth(tableButton)" v-if="$isHasAuth(tableButton)">
					<template slot-scope="{ row }">
						<el-button type="text" v-hasPermi="'57e0bf9df45d47b6a11cc6df792b780a'" @click="handleLookData(row.id)">详情</el-button>
						<template v-if="userRole === 'member'">
							<template v-if="row.isSave === '2' || row.audit === '2'">
								<template v-if="dataType === 'achievement'">
									<el-button type="text" v-hasPermi="'7936af7d326643e0972b1ec007d0cea5'" @click="handleEditAchievement(row.id)">
										编辑
									</el-button>
								</template>
								<template v-else>
									<el-button type="text" v-hasPermi="'7936af7d326643e0972b1ec007d0cea5'" @click="handleOpenForm(row.id)">编辑</el-button>
								</template>
								<el-button type="text" v-hasPermi="'4853ba8c62a44e00ad52a9f79d71ca14'" @click="handleDeleteData(row.id)">删除</el-button>
							</template>
						</template>
						<template v-if="userRole === 'principal'">
							<template v-if="row.audit !== '1'">
								<el-button type="text" v-hasPermi="'7936af7d326643e0972b1ec007d0cea5'" @click="handleEditAchievement(row.id)">编辑</el-button>
								<el-button type="text" v-hasPermi="'0d73cd4619c0444ca1fe210e58fc1979'" @click="handleAuditData(row.id)">审核</el-button>
							</template>
						</template>
						<template v-if="userRole === 'manager'">
							<el-button type="text" v-hasPermi="'7936af7d326643e0972b1ec007d0cea5'" @click="handleManageEdit(row.id)">编辑</el-button>
							<el-button type="text" v-hasPermi="'4853ba8c62a44e00ad52a9f79d71ca14'" @click="handleDeleteData(row.id)">删除</el-button>
						</template>
					</template>
				</el-table-column>
				<el-empty slot="empty" :image-size="120" description="暂无数据"></el-empty>
			</el-table>
		</div>
		<template v-if="dataCount > 0">
			<sw-pagination :total="dataCount" :page.sync="queryData.page" :limit.sync="queryData.limit" @change="queryTableData"></sw-pagination>
		</template>
	</div>
</template>

<script>
import listMixins from '../listMixins1';
import { queryPageList, queryUserPageList, queryAuditPageList, batchDeleteData } from '@/api/business/tbMarvel';
export default {
	mixins: [listMixins],
	computed: {
		dataListRequest() {
			if (this.userRole === 'manager') {
				return queryPageList;
			} else if (this.userRole === 'principal') {
				return queryAuditPageList;
			} else if (this.userRole === 'member') {
				return queryUserPageList;
			}
		},
		topButton() {
			return ['ec854d2ad50a47ffbb61dec5879ff892', '4853ba8c62a44e00ad52a9f79d71ca14'];
		},
		topFrames() {
			return [...this.topButton, this.queryBtn];
		},
		tableButton() {
			let detail = '57e0bf9df45d47b6a11cc6df792b780a';
			if (this.userRole === 'manager') {
				return [detail, '7936af7d326643e0972b1ec007d0cea5', '4853ba8c62a44e00ad52a9f79d71ca14'];
			} else if (this.userRole === 'principal') {
				return [detail, '7936af7d326643e0972b1ec007d0cea5', '0d73cd4619c0444ca1fe210e58fc1979'];
			} else if (this.userRole === 'member') {
				return [detail, '7936af7d326643e0972b1ec007d0cea5', '4853ba8c62a44e00ad52a9f79d71ca14'];
			}
		}
	},
	methods: {
		//请求参数
		formatQueryParams() {
			let params = { ...this.queryData };
			if (this.userRole === 'manager') {
				params['isSave'] = '1';
			}
			return params;
		},
		//获取课题列表数据
		async getTableData() {
			let params = this.formatQueryParams();
			let result = await this.dataListRequest(params).then((res) => res.data);
			this.loading = false;
			if (result.code === '0') {
				this.dataCount = parseInt(result.count);
				this.tableData = result.data || [];
			}
		},

		//删除数据请求
		async deleteDataRequest(id) {
			let params = !id ? this.checkedData.map((n) => n.id) : [id];
			let result = await batchDeleteData(params).then((res) => res.data);
			if (result.code === '0') {
				this.$showCustomMessage('success', `删除数据成功`);
				this.queryTableData();
			}
		},

		//成果类型
		achievementTypeFormatter(data) {
			if (data.filed10 === '1') {
				return '期刊论文';
			} else if (data.filed10 === '2') {
				return '授权专利';
			} else if (data.filed10 === '3') {
				return '会议论文';
			} else if (data.filed10 === '4') {
				return '获得奖项';
			}
		}
	}
};
</script>

<style lang="scss" scoped></style>
